﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using RooHui.Infrastructure.Entities.EFContext;
using RooHui.Infrastructure.Entities.Repository;
using RooHui.Infrastructure.Entities.Enum;

namespace RooHui.Infrastructure.Entities.Entity
{
    public class ProcessStep : IAccessible<P_ProcessStep, ProcessStep>, ILogicEntity<P_ProcessStep, ProcessStep>
    {
        public int ID { get; set; }
        public int ProcessDefID { get; set; }
        public string StepCode { get; set; }
        public string StepName { get; set; }
        public int CurrentProcessID { get; set; }
        public int PreviousProcessID { get; set; }
        public int NextProcessID { get; set; }
        public ItemStatus Status { get; set; }
        public Process CurrentProcess { get; set; }
        public Process NextProcess { get; set; }

        public ProcessStep LoadCurrentProcess(P_Process p_process)
        {
            this.CurrentProcess = new Process().Set(p_process);
            return this;
        }

        public ProcessStep LoadNextProcess(P_Process p_process)
        {
            this.NextProcess = new Process().Set(p_process);
            return this;
        }

        protected override void Covariant(P_ProcessStep model)
        {
            if (model != null)
            {
                this.CurrentProcessID = model.CurrentProcessID;
                this.ID = model.ID;
                this.NextProcessID = model.NextProcessID;
                this.PreviousProcessID = model.PreviousProcessID;
                this.ProcessDefID = model.ProcessDefID;
                this.Status = (ItemStatus)model.Status;
                this.StepCode = model.StepCode;
                this.StepName = model.StepName;
            }
        }

        protected override P_ProcessStep Inverter(ProcessStep model)
        {
            if (model != null)
            {
                return new P_ProcessStep()
                {
                    CurrentProcessID = model.CurrentProcessID,
                    ID = model.ID,
                    NextProcessID = model.NextProcessID,
                    PreviousProcessID = model.PreviousProcessID,
                    ProcessDefID = model.ProcessDefID,
                    Status = (int)model.Status,
                    StepCode = model.StepCode,
                    StepName = model.StepName
                };
            }
            return null;
        }

        public ProcessStep Set(P_ProcessStep dbModel)
        {
            Covariant(dbModel);
            return this;
        }
    }
}
